/*
 * Copyright (c) 2018-2999 九五云信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 */

package com.yami.shop.live.api.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.enums.LiveRoomStatusType;
import com.yami.shop.bean.param.LiveRoomParam;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.live.comment.dto.LiveRoomDto;
import com.yami.shop.live.comment.model.LiveRoom;
import com.yami.shop.live.comment.service.LiveRoomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import ma.glasnost.orika.MapperFacade;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;


/**
 *
 *
 * @author lhd
 * @date 2020-08-05 08:53:17
 */
@RestController
@AllArgsConstructor
@RequestMapping("/live/liveRoom" )
@Api(tags = "直播接口")
public class LiveRoomController {

    private final LiveRoomService liveRoomService;
    private final MapperFacade mapperFacade;

    /**
     * 分页查询
     * @param page 分页对象
     * @return 分页数据
     */
    @GetMapping("/page" )
    @ApiOperation(value = "直播间列表信息", notes = "直播间列表信息")
    public ResponseEntity<IPage<LiveRoomDto>> getLiveRoomPage(PageParam<LiveRoomDto> page, LiveRoomParam liveRoomParam){
        // 如果type为空，则为搜索直播信息
        if(Objects.isNull(liveRoomParam.getSearchType())||StrUtil.isBlank(liveRoomParam.getName())){
            liveRoomParam.setSearchType(1);
            liveRoomParam.setName("");
        }
        liveRoomParam.setRoomTop(0);
        return ResponseEntity.ok(liveRoomService.pageRoomAndDetail(page,liveRoomParam));
    }

    /**
     * 分页查询置顶直播间
     * @param page 分页对象
     * @return 分页数据
     */
    @GetMapping("/pageTopRoom" )
    @ApiOperation(value = "置顶直播间列表信息", notes = "置顶直播间列表信息")
    public ResponseEntity<IPage<LiveRoomDto>> getLiveRoomPageByTop(PageParam<LiveRoomDto> page){
        LiveRoomParam liveRoom = new LiveRoomParam();
        liveRoom.setRoomTop(1);
        liveRoom.setSearchType(1);
        liveRoom.setName("");
        return ResponseEntity.ok(liveRoomService.pageRoomAndDetail(page,liveRoom));
    }

}
